Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Unit-Tests Coverage and CI Workflows #79

Merged
merged 2 commits into from
Apr 11, 2024
Merged

Conversation

gaby
Copy link
Member

@gaby gaby commented Apr 8, 2024

  • Increased tests coveraged from 77.7% to 94.6%. An improvement of 21%
  • Increased tests count from 54 tests to 91 tests
  • Updated all CI workflows to match https://github.com/gofiber/fiber
  • Added Apple-M14 platform
  • Added Makefile to ease development/testing
  • Added unit-tests to all the core functions/paths missing
  • Updated golanci-lint to latest version with the config similar to https://github.com/gofiber/fiber
  • Added extra benchmarks

Fixes #68

@gaby gaby requested a review from a team as a code owner April 8, 2024 01:59
@gaby gaby requested review from sixcolors, ReneWerner87 and efectn and removed request for a team April 8, 2024 01:59
Copy link

coderabbitai bot commented Apr 8, 2024

Walkthrough

The recent modifications streamline and enhance the development workflow for a Go project, focusing on better code quality and performance. Updates include the adoption of golangci-lint, improved Go version support, and the integration of gotestsum for testing. Changes to file handling and testing assert a commitment to robustness and clarity. This overhaul signifies a stride towards modernization and efficiency in the project's lifecycle.

Changes

Files Change Summary
.github/workflows/... Updated Go versions, added macos-14, integrated golangci-lint, and improved test outputs with gotestsum.
.gitignore, README.md Minor updates for ignoring coverage reports and badge link adjustments.
Makefile, .golangci.yml Introduced new commands for development tasks and configured golangci-lint.
*_test.go Enhanced tests with new functions, refactored benchmarks, and used require.True.
common.go, convert.go, ... Code clarity improvements, updated error handling, and added type support in conversions.

Assessment against linked issues

Objective Addressed Explanation
Add golangci-lint with config as on the main repo. (#68)
Update unit test workflows to utilize gotestsum. (#2885)
Enable go-require rule for testify-lint and address failing tests related to testify. (#2891) The PR introduces significant updates, but it's unclear if the specific go-require rule and all related failing tests are addressed without detailed test outcomes.

Possibly related issues

🐰 A Rabbit's Ode to Code 🌟

In the burrow of the bits, where the digital carrots grow,
A rabbit hopped with code, making the tests all glow.
With a flip and a skip, golangci-lint was set,
Ensuring the code was as sharp as it could get.
📈 For performance and style, it did not forget,
A leap towards the future, without a single regret.
🚀 In the land of Go, our code now flies jet-set!

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

codecov bot commented Apr 8, 2024

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 94b19de and fe1c286.
Files ignored due to path filters (1)
  • go.mod is excluded by !**/*.mod
Files selected for processing (20)
  • .github/workflows/benchmark.yml (1 hunks)
  • .github/workflows/linter.yml (1 hunks)
  • .github/workflows/test.yml (2 hunks)
  • .gitignore (1 hunks)
  • .golangci.yml (1 hunks)
  • Makefile (1 hunks)
  • README.md (1 hunks)
  • bytes_test.go (1 hunks)
  • byteseq_test.go (2 hunks)
  • common.go (2 hunks)
  • common_test.go (7 hunks)
  • convert.go (1 hunks)
  • convert_test.go (6 hunks)
  • file.go (7 hunks)
  • file_test.go (5 hunks)
  • http_test.go (3 hunks)
  • ips.go (1 hunks)
  • ips_test.go (3 hunks)
  • time_test.go (2 hunks)
  • xml_test.go (2 hunks)
Files skipped from review due to trivial changes (1)
  • Makefile
Additional Context Used
GitHub Check Runs (1)
codecov/patch success (3)

file.go: [warning] 57-57: file.go#L57
Added line #L57 was not covered by tests


file.go: [warning] 76-76: file.go#L76
Added line #L76 was not covered by tests


file.go: [warning] 82-82: file.go#L82
Added line #L82 was not covered by tests

Additional comments not posted (40)
.gitignore (1)

14-14: Adding coverage.html to .gitignore is a good practice to avoid committing generated files. Well done.

.github/workflows/linter.yml (4)

1-1: Changing the workflow name to golangci-lint clarifies its purpose. Good choice.


6-11: Updating path configurations to include all files except those in docs and Markdown files is a sensible approach to trigger the workflow only on meaningful changes.

Also applies to: 13-16


18-24: Adding permissions for content, pull requests, and checks access is a good security practice, ensuring the workflow has only the necessary permissions.


27-43: Adjusting the job setup to include the latest Go version and specifying the golangci-lint version ensures consistency with the project's environment. Remember to keep these versions updated as part of regular maintenance.

.github/workflows/test.yml (3)

21-22: Updating the Go versions and adding macos-14 to the testing matrix ensures compatibility across the latest platforms and Go versions. This is a proactive approach to maintaining the project.


33-40: Adding gotestsum for test execution and adjusting test commands enhances the readability and utility of test outputs. This change improves the developer experience by providing more structured test results.


42-49: Uploading coverage reports to Codecov for specific platforms and Go versions is a great way to track test coverage over time. Ensure that the CODECOV_TOKEN is securely stored and access is limited.

time_test.go (2)

10-13: Changing the assertion method in checkTimeStamp to require.True with a condition for time buffer is a practical approach to handle potential timing discrepancies in tests.


34-65: Adding assertions and timer resets in benchmark functions is a good practice. It ensures the benchmarks are accurately measuring the intended operations. Remember to review the benchmark results for any significant changes.

.github/workflows/benchmark.yml (3)

6-16: Updating paths configuration to trigger the workflow on meaningful changes is a good practice. It avoids unnecessary runs on documentation updates.


22-29: Updating the Go version in the setup step ensures benchmarks are run against the current project environment. Consistency between the project environment and benchmarking environment is crucial.


31-52: Adjusting steps for running benchmarks, caching, and saving benchmark results aligns with best practices for performance testing. Using actions for caching and benchmark comparison helps in tracking performance over time.

file_test.go (3)

4-4: Adding the fmt package import to support error formatting in new test functions is necessary. Good attention to detail.


56-62: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [40-73]

Renaming neededResults to expectedResults and adjusting assertion parameters improves readability and clarity in test cases. Consistent naming conventions enhance the maintainability of test code.


75-96: Adding Test_Walk_Error and Test_ReadFile_Error functions to test error cases is an excellent practice. It ensures robust error handling and coverage of edge cases in the code.

byteseq_test.go (1)

11-35: Adding Test_EqualFold to test case-insensitive comparisons of string and byte slices is a valuable addition. It covers various cases and uses require.Equal for assertions, ensuring the function behaves as expected.

bytes_test.go (2)

24-32: Adding Test_ToUpperBytes to test the ToUpperBytes function with multiple cases is a good practice. It ensures the function works as expected across a variety of inputs.


38-49: Refactoring benchmark functions to use require.True for comparison instead of require.Equal is appropriate. However, ensure that the benchmarks are focused on measuring performance rather than correctness, which should be covered by unit tests.

ips.go (1)

3-5: The change to a multi-line import block enhances readability and maintainability.

file.go (4)

4-4: Adding the errors package to utilize errors.Is for error handling is a good practice for more precise error comparison.


22-22: Renaming walk to walkInternal improves clarity by indicating it's an internal helper function.


57-57: Using errors.Is for error comparison is a best practice, enhancing the robustness of error handling.


57-57: Ensure new error handling logic is covered by tests.

Also applies to: 76-76, 82-82

xml_test.go (2)

72-73: Updating assertions to require.NoError and require.Len improves clarity and specificity in test expectations.


79-99: Adding benchmark functions for XML encoding and decoding is valuable for tracking performance regressions or improvements.

Also applies to: 101-121, 123-138

convert.go (1)

139-146: The added comments clarify why error checking is omitted, enhancing code readability and maintainability.

http_test.go (2)

96-97: Adding new test cases improves coverage and ensures the function handles edge cases correctly.


103-103: Removing unnecessary assignments in benchmark functions simplifies the code and may slightly improve benchmark accuracy.

Also applies to: 109-109, 145-145, 150-150

ips_test.go (1)

17-41: Updating assertions to require.True and require.False and adding new test cases for IPv6 addresses enhance test clarity and coverage.

Also applies to: 46-76

common_test.go (3)

10-11: Adding imports for net and os packages supports the new test functions added in this file.


29-30: Refactoring assertions to use require.Len and require.NotEqual improves the clarity and specificity of test expectations.

Also applies to: 54-55


100-111: Adding new test functions Test_GetArgument and Test_IncrementIPRange increases test coverage and ensures functionality correctness.

Also applies to: 113-134

common.go (1)

55-73: Renaming the variable uuid to _uuid in the UUID function improves clarity by distinguishing it from the uuid package.

README.md (1)

5-7: LGTM! The addition of the Codecov badge and reordering of the Discord badge are appropriate updates.

convert_test.go (4)

15-30: LGTM! The modernization to []any and the addition of MyStringer and CustomType for testing purposes are well-implemented.


47-60: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [33-57]

LGTM! The updates to dataTypeExamples and the ToString test cases enhance the test coverage by including a wider variety of data types.

Also applies to: 82-126


161-197: LGTM! The comprehensive tests for CopyBytes and ByteSize functions are well-designed to ensure correctness and robustness.


263-296: LGTM! The updates to benchmarks for UnsafeBytes and UnsafeString provide valuable insights into performance comparisons.

.golangci.yml (1)

1-383: Consider addressing the TODO comments throughout the .golangci.yml configuration to further refine linting practices and ensure alignment with best practices.

@gaby gaby changed the title Improvements to Unit-Tests Coverage and CI Workflows Improve Unit-Tests Coverage and CI Workflows Apr 10, 2024
common.go Show resolved Hide resolved
@ReneWerner87 ReneWerner87 merged commit 5c19157 into master Apr 11, 2024
18 checks passed
@sixcolors sixcolors deleted the ci-lint-updates branch April 11, 2024 13:33
@gaby gaby mentioned this pull request Apr 11, 2024
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🚀 [Feature]: Add golangci-lint
4 participants